package com.moter.demo01.juc.functioninterface;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Stream;

public class StreamDemo {
    public static void main(String[] args) {
        List<User> users = new ArrayList<>();
        users.add(new User().setAge(19).setName("moter").setId(1));
        users.add(new User().setAge(20).setName("mote").setId(2));
        users.add(new User().setAge(21).setName("mot").setId(3));
        users.add(new User().setAge(22).setName("mo").setId(4));
        users.add(new User().setAge(23).setName("m").setId(5));
        Stream<User> sorted = users.stream()
                .filter(user -> user.getId() % 2 == 0)
                .filter(user -> user.getAge() >= 20)
                .map(user -> user.setName(user.getName().toUpperCase()))
                .sorted(Comparator.comparing(User::getName));
//        sorted.forEach((user -> {
//            System.out.println(user);
//        }));
        System.out.println(sorted.toArray()[0]);
    }
    static class User{
        private String name;
        private Integer age;
        private Integer id;

        @Override
        public String toString() {
            return "User{" +
                    "name='" + name + '\'' +
                    ", age=" + age +
                    ", id=" + id +
                    '}';
        }

        public  String getName() {
            return name;
        }

        public User setName(String name) {
            this.name = name;
            return this;
        }

        public Integer getAge() {
            return age;
        }

        public User setAge(Integer age) {
            this.age = age;
            return this;
        }

        public Integer getId() {
            return id;
        }

        public User setId(Integer id) {
            this.id = id;
            return this;
        }
    }
}
